package com.example.shopping_web_back.service;

import com.example.shopping_web_back.service.impl.EmailServiceImpl;
import jakarta.mail.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService implements EmailServiceImpl {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public void sendEmailWithVerificationCode(String to, String subject, String verificationCode) throws MessagingException {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("3490136641@qq.com");
        message.setTo(to);
        message.setSubject(subject);
        message.setText("您的验证码为：" + verificationCode);
        try {
            javaMailSender.send(message);
            System.out.println("邮件发送成功");
        } catch (Exception e) {
            System.out.println("邮件发送失败!" + e.getMessage());
        }
    }
}
